package cn.lj.org.controller;

import cn.lj.base.Exception.BusinessException;
import cn.lj.base.util.AjaxResult;
import cn.lj.org.domain.Shop;
import cn.lj.org.service.impl.ShopServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //@Controller+@ResponseBody(转换json)
@RequestMapping("/shop")
@Api(tags = "店铺接口",description = "店铺接口详细描述")
public class ShopController {
    @Autowired
    private ShopServiceImpl shopService;

    @GetMapping
    @ApiOperation(value = "店铺查找",notes = "查找所有店铺")
    public List<Shop> findAll(){
        List<Shop> list = shopService.getAll();
        return list;
    }
    @PostMapping("/settledIn")
    @ApiOperation(value = "店铺入驻",notes = "店铺入驻以及员工")
    public AjaxResult settledIn(@RequestBody Shop shop){
        try {
            shopService.settledIn(shop);
            return AjaxResult.me();
        }catch (BusinessException e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }catch (Exception e){
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }
    }
    @PostMapping("/{id}")
    @ApiOperation(value = "修改状态",notes = "根据ID修改店铺状态")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            shopService.updateState(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setAjaxResult(e.getMessage());
        }
    }
}
